package cn.szzsi.business.apiservice;



import cn.szzsi.aci.dto.CompanyInfoDto;
import cn.szzsi.aci.service.ConfigInterface;
import cn.szzsi.model.CompanyInfo;

import cn.szzsi.model.Resource;
import com.jfinal.json.FastJson;
import com.jfinal.kit.JsonKit;
import com.jfinal.kit.StrKit;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by admin on 2017/7/11.
 */
public class ConfigService implements ConfigInterface {

    /**
     * 获取短信签名
     * @param shopId
     * @return
     */
    @Override
    public String getSmsSignature(String shopId) {
        CompanyInfo co=CompanyInfo.dao.getByShopId(shopId);
        if(co!=null){
            String smsSignature=co.getSmsSignature();
            if(StrKit.notBlank(smsSignature)){
                return smsSignature;
            }else{
                return "微米荟商城";
            }
        }else{
            return "微米荟商城";
        }

    }

    /**
     * 获取品牌名称
     * @param shopId
     * @return
     */
    @Override
    public String getBrandName(String shopId) {
        CompanyInfo companyInfo=CompanyInfo.dao.getByShopId(shopId);
        if(companyInfo!=null){
            return companyInfo.getBrandName();
        }else {
            return null;
        }
    }

    /**
     * 获取品牌LOGO
     * @param shopId
     * @return
     */
    @Override
    public String getBrandLogo(String shopId) {
        CompanyInfo companyInfo=CompanyInfo.dao.getByShopId(shopId);
        if(companyInfo!=null){
            return companyInfo.getBrandLogo();
        }else {
            return null;
        }
    }

    @Override
    public CompanyInfoDto getCompanyInfo(String shopId) {
        CompanyInfo companyInfo=CompanyInfo.dao.getByShopId(shopId);
        if(companyInfo!=null){
            FastJson fastJson=new FastJson();
            CompanyInfoDto companyInfoDto=fastJson.parse(JsonKit.toJson(companyInfo),CompanyInfoDto.class);
            return companyInfoDto;
        }else{
            return null;
        }
    }

    @Override
    public List<CompanyInfoDto> getAllCompanyInfo() {
        List<CompanyInfo> companyInfos=CompanyInfo.dao.getAll("2");
        List<CompanyInfoDto>companyInfoDtos=new ArrayList<CompanyInfoDto>();
        for (CompanyInfo companyInfo:companyInfos){
                FastJson fastJson=new FastJson();
                CompanyInfoDto companyInfoDto=fastJson.parse(JsonKit.toJson(companyInfo),CompanyInfoDto.class);
                companyInfoDtos.add(companyInfoDto);
        }
        return companyInfoDtos;
    }


}
